import { PatientsItem } from '@/interfaces/patients'
import type { ProColumns } from '@ant-design/pro-components';
import { Button } from 'antd';
import { deletePatient } from '@/services/patients'
import deleteConfirm from '@/utils/deleteConfirm'
import { ActionType } from '@ant-design/pro-table';
import WithAuthComp from '@/components/WithAuthComp';
import { ROLE } from '@/common/const'

const getColumns: (dialogRef, setReadonly, setId) => ProColumns<PatientsItem>[] = (dialogRef, setReadonly, setId) => {
    return [
        {
            title: '胸牌号',
            dataIndex: 'patientnumber',
            copyable: true,
        },
        {
            title: '姓名',
            dataIndex: 'name',
        },
        {
            title: '监区',
            dataIndex: 'jq',
            sorter: true
        },
        {
            title: '出生日期',
            dataIndex: 'birthday',
            hideInSearch: true
        },
        {
            title: '操作',
            valueType: 'option',
            key: 'option',
            width: 300,
            render: (text, record, _, action) => [
                <Button
                    color="cyan"
                    size='small'
                    type='primary'
                    key='detail'
                    onClick={() => {
                        setReadonly(true)
                        setId(record.patientnumber)
                        dialogRef?.current?.showModelRef('患者详情');
                    }}
                >
                    详情
                </Button>,
                <WithAuthComp authKey={[ROLE.ADMIN, ROLE.YS, ROLE.HS]} key='edit'>
                    <Button
                        size='small'
                        type='primary'

                        onClick={() => {
                            setReadonly(false)
                            setId(record.patientnumber)
                            dialogRef?.current?.showModelRef('编辑患者');
                        }}
                    >
                        编辑
                    </Button>
                </WithAuthComp>,
                <WithAuthComp authKey={[ROLE.ADMIN]} key='delete'>
                    <Button
                        size='small'
                        type="primary"

                        danger
                        onClick={() => {
                            deleteConfirm({ id: record.patientnumber, action: action as ActionType, deleteApi: deletePatient })
                        }}
                    >
                        删除
                    </Button>
                </WithAuthComp>
            ],
        },
    ];
}

export default getColumns;